package com.hhh.petadopt.serviceImpl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hhh.petadopt.mapper.SearchMapper;
import com.hhh.petadopt.pojo.News;
import com.hhh.petadopt.service.SeachService;
/**
 * 搜索管理
 * @author 杜镇声声
 *
 */
@Service
public class SeachServiceImpl implements SeachService {
	@Autowired
	private SearchMapper searchMapper;

	//查询符合条件的总条数
	@Override
	public Integer selectNewsCountByWords(String word) {
		Integer count = searchMapper.selectCountByWord(word);
		return count;
	}

	//查询符合条件的新闻列表
	@Override
	public List<News> selectNewsByWord(String word) {
		List<News> newsList = searchMapper.selectNewsByWord(word);
		//将新闻日期转换为yyyy-mm-dd格式
		List<News> nList = new ArrayList<News>();
		for (News news : newsList) {
			news.setCreated(news.getCreated().substring(0, 10));
			nList.add(news);
		}
		return nList;
	}

}
